set more off
clear
				
cd "/Volumes/LACIE/JFIES_ORG_2013"
use "./VAT_Japan/JFIES_VAT.dta", clear
tsset id period, m

global cons_d_log_var "d_log_m_tot_exp_def d_log_m_d_gs_def d_log_m_snd_gs_def d_log_m_nd_gs_def d_log_m_exempt_gs_def"
global d_demo_var "age d_number_member d_number_worker d_number_member_18 d_number_member_65"
global monthd "d_month_1-d_month_9 d_month_11 d_month_12"


***************************************************************
***************************************************************
*****  Sample Selection         *******************************
***************************************************************
***************************************************************

tsset id period, m

drop if period<m(1990m3)|period>m(2004m3)

egen all=count(id), by(id)
gen jobchgm=interview>1&(job!=L.job) if all==6&job!=12
egen jobchg=sum(jobchgm), by(id)
drop jobchgm
gen hhchgm=interview>1&(sex!=L.sex|D.age!=0) if all==6&job!=12&jobchg==0
egen hhchg=sum(hhchgm), by(id)
drop hhchgm

gen sample_selection=(id>1992030000&period>=m(1992m4)&period<=m(2002m3)&all==6&job!=12&jobchg==0&hhchg==0&sex==1)

***************************************************************
***************************************************************
*****   Table 2 Summary Statistics  ***************************
***************************************************************
***************************************************************

su age number_member number_member_15 number_member_65 number_worker yearly_income m_tot_exp_all_def m_tot_exp_def m_nd_gs_def m_snd_gs_def m_d_gs_def if L.id!=.&sample_selection 

***************************************************************
***************************************************************
*****   Table 3 Baseline Regression  **************************
***************************************************************
***************************************************************

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var y1997_m4 if sample_selection [w=inflation_factor], cluster(id)

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m2-d_y1997_m6 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
test d_y1997_m2 d_y1997_m3 d_y1997_m4 d_y1997_m5 d_y1997_m6
test y1996_m10+y1996_m11+y1996_m12=0

***************************************************************
***************************************************************
*****   Table 4 Robustness Check: Different Sample  ***********
***************************************************************
***************************************************************

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if period>=m(1993m4)&period<=m(2001m3)&all==6&job!=12&jobchg==0&hhchg==0&sex==1 [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if period>=m(1994m4)&period<=m(2000m3)&all==6&job!=12&jobchg==0&hhchg==0&sex==1 [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if id>1992030000&period>=m(1992m4)&period<=m(2002m3) [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0


***************************************************************
***************************************************************
*****   Table 5 Heterogeneity Across Household Type  **********
***************************************************************
***************************************************************

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if sample_selection&job!=10 [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if sample_selection&job==10 [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if sample_selection&yearly_income>60 [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if sample_selection&yearly_income<=60 [w=inflation_factor], cluster(id)
test y1996_m10+y1996_m11+y1996_m12=0


***************************************************************
***************************************************************
**  Table 6 Arbitrage Effects for Storable and Nondurables  ***
***************************************************************
***************************************************************

ivreg2 d_log_m_nd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m2-d_y1997_m6 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
test d_y1997_m2 d_y1997_m3 d_y1997_m4 d_y1997_m5 d_y1997_m6

ivreg2 d_log_m_snd_gs_def $monthd d_interview_* $d_demo_var d_y1997_m2-d_y1997_m6 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
test d_y1997_m2 d_y1997_m3 d_y1997_m4 d_y1997_m5 d_y1997_m6

ivreg2 d_log_m_d_gs_def $monthd d_interview_* $d_demo_var d_y1997_m2-d_y1997_m6 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
test d_y1997_m2 d_y1997_m3 d_y1997_m4 d_y1997_m5 d_y1997_m6


***************************************************************
***************************************************************
*Appendix Table 1. Testing the Additive Separavility of  Tax-Exempt Goods***
***************************************************************
***************************************************************
*/

ivreg2 d_log_m_exempt_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
ivreg2 d_log_m_exempt_gs_def $monthd d_interview_* $d_demo_var d_y1997_m3-d_y1997_m4 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)
ivreg2 d_log_m_exempt_gs_def $monthd d_interview_* $d_demo_var d_y1997_m2-d_y1997_m4 y1996_m1* y1997_m4 if sample_selection [w=inflation_factor], cluster(id)

